#!/bin/sh
cd ${0%/*} || exit 1    # run from this directory

# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions

mkdir -p constant/polyMesh

if [ "$1" != "" ]
    then foil=$1
else
    foil="0012"
fi

if [ "$2" != "" ]
    then alpha_deg=$2
else
    alpha_deg=4
fi

parallel=false

cp -rf 0.org 0
python scripts/blockmeshdict.py $foil $alpha_deg
runApplication blockMesh
runApplication createPatch -overwrite
# runApplication refineMesh -all -overwrite

if [ $parallel = true ]
    then
    runApplication decomposePar
    nProc=$(getNumberOfProcessors)
    runParallel pimpleFoam $nProc
    runApplication reconstructPar
else
    runApplication pimpleFoam
fi

runApplication sample -latestTime
runApplication yPlus -latestTime
